unit listaDeposito;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, Grids,
  DBGrids, RXDBCtrl, Menus, Buttons, StdCtrls;

type
  TfrmListaDeposito = class(TForm)
    RxDBGrid1: TRxDBGrid;
    cdsLista: TSQLClientDataSet;
    sLista: TDataSource;
    cdsListaID_MATERIAL: TIntegerField;
    cdsListaCANT: TFloatField;
    cdsListaMATERIAL: TStringField;
    pop: TPopupMenu;
    RetirarMaterial1: TMenuItem;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    btnExcel: TSpeedButton;
    SpeedButton3: TSpeedButton;
    NuevoMaterial1: TMenuItem;
    IngresoMaterial1: TMenuItem;
    NuevoMaterial2: TMenuItem;
    Label1: TLabel;
    edtFiltroGral: TEdit;
    btnDesfiltrarGral: TBitBtn;
    lblRegistros: TLabel;
    Label3: TLabel;
    procedure RetirarMaterial1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure btnExcelClick(Sender: TObject);
    procedure NuevoMaterial1Click(Sender: TObject);
    procedure edtFiltroGralChange(Sender: TObject);
    procedure btnDesfiltrarGralClick(Sender: TObject);
    procedure sListaDataChange(Sender: TObject; Field: TField);
  private
    Fusuario: word;
    procedure Setusuario(const Value: word);
    { Private declarations }
  published
    property usuario: word read Fusuario write Setusuario;
  public
    constructor CreateNuevo(AOwner: TComponent; usuario: word);
    procedure refrescar;

  end;

var
  frmListaDeposito: TfrmListaDeposito;

implementation

uses MDatos, retiroMaterial, deposito, movDeposito, Recursos;

{$R *.dfm}

{ TForm1 }

constructor TfrmListaDeposito.CreateNuevo(AOwner: TComponent; usuario: word);
begin
  inherited Create(Aowner);
  self.usuario := usuario;
  self.cdsLista.Open;
  self.ShowModal;
  
end;

procedure TfrmListaDeposito.Setusuario(const Value: word);
begin
  Fusuario := Value;
end;

procedure TfrmListaDeposito.RetirarMaterial1Click(Sender: TObject);
begin
  if not self.cdsListaID_MATERIAL.IsNull and not (self.cdsListaID_MATERIAL.AsInteger = 0) then
    TfrmRetiroMaterial.CreateNuevo(self, 0, self.cdsListaID_MATERIAL.AsInteger, 0)
  else
    Application.MessageBox('Debe seleccionar un material', 'Error', mb_Ok+mb_IconError); 
end;

procedure TfrmListaDeposito.refrescar;
begin
  self.cdsLista.Close;
  self.cdsLista.Open;
end;

procedure TfrmListaDeposito.SpeedButton1Click(Sender: TObject);
begin
  TfrmDeposito.CreateNuevo(self, 0, 0, '', 0);
end;

procedure TfrmListaDeposito.SpeedButton3Click(Sender: TObject);
begin
  TfrmMovDeposito.CreateNuevo(self);
end;

procedure TfrmListaDeposito.btnExcelClick(Sender: TObject);
begin
  abrirEnExcel(self, self.cdsLista, nil, nil, 'LISTADO DE MATERIALES EN DEPOSITO', '');
end;

procedure TfrmListaDeposito.NuevoMaterial1Click(Sender: TObject);
begin
  TfrmDeposito.CreateNuevo(self, 0, self.cdsListaID_MATERIAL.AsInteger, self.cdsListaMATERIAL.AsString, 0);
end;

procedure TfrmListaDeposito.edtFiltroGralChange(Sender: TObject);
begin
  self.cdsLista.Filtered := False;
  if (self.edtFiltroGral.Text <> '') then
  begin
    self.cdsLista.Filter := 'MATERIAL like ''%'+self.edtFiltroGral.Text+'%''';
    self.cdsLista.Filtered := True;
  end;
  self.btnDesfiltrarGral.Enabled := self.cdsLista.Filtered;
end;

procedure TfrmListaDeposito.btnDesfiltrarGralClick(Sender: TObject);
begin
  self.edtFiltroGral.Text := '';
end;

procedure TfrmListaDeposito.sListaDataChange(Sender: TObject;
  Field: TField);
begin
  self.lblRegistros.Caption := IntToStr(self.cdsLista.RecordCount);
end;

end.
